/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import algorithm.GeneticAlgo;
import algorithm.ProblemData;
import algorithm.Solution;
import java.io.File;

/**
 *
 * @author Lu
 */
public class GeneticTest {

    public static void main(String[] args) {
        String folderPath = ".\\data\\";
        File folder = new File(folderPath);
        String[] filesList = folder.list();

        // Paramètres de l'algorithme
        int popSize = 20;
        float mutationProba = 0.3f;
        float selectionProba = 0.9f;
        int nbIter = 200;

        float startAverageEvaluationByDataSize = 0;
        float endAverageEvaluationByDataSize = 0;
        int dataSize = 0;
        for (String file : filesList) {
            File dataFile = new File(folderPath + file.substring(0, file.length()));
            ProblemData pb = new ProblemData(dataFile, 2);

            float startAverageEvaluation = 0;
            float endAverageEvaluation = 0;
            int i;
            for (i = 0; i < 100; i++) {
                GeneticAlgo algo = new GeneticAlgo(popSize, pb);
                Solution bestSol = algo.getBestCurrentSolution();
                int tempsMinAvant = bestSol.getSolutionEvaluation();
                int tempsMinApres;
                for (int j = 0; j < nbIter; j++) {
                    algo.mutation(mutationProba);
                    algo.crossover();
                    algo.selection(selectionProba);
                }
                tempsMinApres = algo.getBestCurrentSolution().getSolutionEvaluation();
                startAverageEvaluation = startAverageEvaluation + tempsMinAvant;
                endAverageEvaluation = endAverageEvaluation + tempsMinApres;

            }
            startAverageEvaluation = startAverageEvaluation / i;
            endAverageEvaluation = endAverageEvaluation / i;

            if (dataSize == 0 || dataSize == pb.getMachineNb()) {
                startAverageEvaluationByDataSize += startAverageEvaluation;
                endAverageEvaluationByDataSize += endAverageEvaluation;
            } else {
                startAverageEvaluationByDataSize /= 10;
                System.out.println("Temps moyen avant algo pour matrice de taille " + dataSize + " : "
                        + startAverageEvaluationByDataSize);
                startAverageEvaluationByDataSize = startAverageEvaluation;
                endAverageEvaluationByDataSize /= 10;
                System.out.println("Temps moyen après algo pour matrice de taille " + dataSize + " : "
                        + endAverageEvaluationByDataSize);
                endAverageEvaluationByDataSize = endAverageEvaluation;
            }
            dataSize = pb.getMachineNb();

        }
        startAverageEvaluationByDataSize /= 10;
        System.out.println("Temps moyen avant algo pour matrice de taille " + dataSize + " : "
                + startAverageEvaluationByDataSize);
        endAverageEvaluationByDataSize /= 10;
        System.out.println("Temps moyen avant algo pour matrice de taille " + dataSize + " : "
                + endAverageEvaluationByDataSize);
    }
}
